<?php

require_once('../Controller/UserController.php');

function CheckUser($login,$sha1)
{
  $userHandler = new UserController();
  if ( $userHandler->adminHasCredential($login, $sha1) )
    return true;
  return false;
}

if(!isset($_POST['sha1']))
{
  header("Location: ../login.php?status=nopwd");
  die();
}
$sha1=$_POST['sha1'];

if(!isset($_POST['login']))
{
  header("Location: ../login.php?status=nologin");
  die();
}
$login=$_POST['login'];

if(!CheckUser($login,$sha1))
{
  header("Location: ../login.php?status=incorrect");
  die();
}

session_start();

$_SESSION['last_access']=time();
$_SESSION['ipaddr']=$_SERVER['REMOTE_ADDR'];
$_SESSION['user']=$login;

header("Location: ../espace_administration.php");

